/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.web.service;

import java.math.BigDecimal;
import java.util.List;

import com.jeeplus.modules.web.entity.WxOrder;
import com.jeeplus.modules.web.entity.WxUser;
import com.jeeplus.modules.web.entity.WxUserWalletDetails;
import com.jeeplus.modules.web.mapper.WxOrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.web.entity.WxUserWallet;
import com.jeeplus.modules.web.mapper.WxUserWalletMapper;

/**
 * 钱包Service
 * @author rongjie
 * @version 2017-08-24
 */
@Service
@Transactional(readOnly = true)
public class WxUserWalletService extends CrudService<WxUserWalletMapper, WxUserWallet> {

	@Autowired
	private WxOrderMapper wxOrderMapper;
	@Autowired
	private WxUserWalletDetailsService wxUserWalletDetailsService;

	public WxUserWallet get(String id) {
		return super.get(id);
	}

	public List<WxUserWallet> findList(WxUserWallet wxUserWallet) {
		return super.findList(wxUserWallet);
	}

	public Page<WxUserWallet> findPage(Page<WxUserWallet> page, WxUserWallet wxUserWallet) {
		return super.findPage(page, wxUserWallet);
	}

	@Transactional(readOnly = false)
	public void save(WxUserWallet wxUserWallet) {
		super.save(wxUserWallet);
	}

	@Transactional(readOnly = false)
	public void delete(WxUserWallet wxUserWallet) {
		super.delete(wxUserWallet);
	}
	@Transactional(readOnly = false)
	public void setAddMoney(String orderMoney, String addOrderMoney, String orderNumber,String content) {
		this.mapper.setAddMoney(orderMoney,addOrderMoney,orderNumber);
		//增加流水
		WxOrder wxOrder = wxOrderMapper.getOrder(orderNumber);
		WxUserWalletDetails wxUserWalletDetails = new WxUserWalletDetails();
		wxUserWalletDetails.setContent(content);
		wxUserWalletDetails.setPrice(new BigDecimal(orderMoney));
		wxUserWalletDetails.setOrderNumber(orderNumber);
		wxUserWalletDetails.setUser(wxOrder.getUser());
		wxUserWalletDetails.setCreateBy(wxOrder.getCreateBy());
		wxUserWalletDetails.setUpdateBy(wxOrder.getUpdateBy());
		wxUserWalletDetailsService.save(wxUserWalletDetails);
	}

	@Transactional(readOnly = false)
	public void setDelMoney(String id, Double money,String content,String orderNumber ) {
		this.mapper.setDelMoney(id,money);
		//增加流水
		WxUserWalletDetails wxUserWalletDetails = new WxUserWalletDetails();
		wxUserWalletDetails.setContent(content);
		wxUserWalletDetails.setOrderNumber(orderNumber);
		wxUserWalletDetails.setPrice(new BigDecimal(money*-1));
		WxUser wxUser = new WxUser(id);
		wxUserWalletDetails.setUser(wxUser);
		wxUserWalletDetailsService.save(wxUserWalletDetails);
	}
	@Transactional(readOnly = false)
	public void setAddIntegration(String id, int intValue) {
		this.mapper.setAddIntegration(id,intValue);
	}
	@Transactional(readOnly = false)
	public void setIntegration(String id, int intValue) {
		this.mapper.setIntegration(id,intValue);
	}
}
